package lesson16;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.LongAdder;

public class MyLongAdder {

    public static void main(String[] args) throws InterruptedException {
        LongAdder count = new LongAdder();
        ExecutorService executorService = Executors.newFixedThreadPool(16);
        MyTask myTask = new MyTask(count);
        for(int i = 0; i < 1000; i++){
            executorService.submit(myTask);
        }
        myTask.join();

        Thread.sleep(1000);

        System.out.println(count.longValue());
    }

    static class MyTask extends Thread{

        private LongAdder count;

        MyTask(LongAdder count){
            this.count = count;
        }

        @Override
        public void run() {
            count.increment();
        }
        
    }
}
